package suanfa;

public class Allperm {
    public static void main(String[] args) {
        String s = "abcdef";
        perm(s.toCharArray(),0,s.length()-1);
    }

    public static void swap(char[] str, int a, int b) {
        char t = str[a];
        str[a] = str[b];
        str[b] = t;
    }

    public static void perm(char[] str, int from, int to) {
        if (from == to) {
            System.out.println(str);
            return;
        }
        for (int i = from; i <= to; i++) {
            swap(str, from, i);
            perm(str, from + 1, to);
            swap(str, from, i);
        }
    }
}
